Skip to content

refactor(permission-controller): decouple permission middleware via messenger actions#8532

Open
rekmarks wants to merge 9 commits intofb/create-method-middlewarefrom
rekm/permission-methodmiddleware
Open

refactor(permission-controller): decouple permission middleware via messenger actions#8532
rekmarks wants to merge 9 commits intofb/create-method-middlewarefrom
rekm/permission-methodmiddleware

Conversation

@rekmarks
Copy link
Copy Markdown
Member

@rekmarks rekmarks commented Apr 20, 2026

Advances #4238
Reverts #8502

  • Rewrites permission-middleware.ts as a standalone createPermissionMiddleware({ messenger, subject }) factory that dispatches through the PermissionController:executeRestrictedMethod and PermissionController:hasUnrestrictedMethod messenger actions instead of bound controller hooks. Removes the createPermissionMiddleware property from PermissionController.
  • Exposes hasUnrestrictedMethod as a public method / messenger action, and makes getRestrictedMethod #-private (it has no remaining external consumers now that the middleware goes through the messenger).
  • When a restricted method returns undefined, the middleware now propagates the plain Error thrown by executeRestrictedMethod; the JSON-RPC engine serializes it as a standard internal error response instead of a custom internalError with a request data payload.

Note

Medium Risk
Breaking API change removes PermissionController.createPermissionMiddleware in favor of standalone middleware factories and new messenger actions, so downstream integrations must be updated. Behavior around error propagation changes slightly (e.g., undefined restricted-method results now surface as generic internal errors), which could affect callers/tests.

Overview
Decouples permission enforcement middleware from PermissionController. The controller no longer exposes createPermissionMiddleware; instead the package exports standalone createPermissionMiddleware (legacy JsonRpcEngine, now deprecated) and createPermissionMiddlewareV2 (JsonRpcEngineV2) that route enforcement through messenger calls.

Adds messenger-exposed APIs needed by the new middleware (PermissionController:hasUnrestrictedMethod and PermissionController:executeRestrictedMethod), makes getRestrictedMethod private, and updates tests/docs/changelog to reflect the new integration pattern and v2 engine support. Error handling is adjusted so undefined restricted-method results propagate as a plain Error (serialized by the engine as a standard internal error) rather than a custom JSON-RPC internalError payload.

Reviewed by Cursor Bugbot for commit 9eb56a6. Bugbot is set up for automated code reviews on this repo. Configure here.

@rekmarks rekmarks requested review from a team as code owners April 20, 2026 23:43
@rekmarks rekmarks marked this pull request as draft April 20, 2026 23:54
@rekmarks
Copy link
Copy Markdown
Member Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 706f8dc. Configure here.

@FrederikBolding FrederikBolding force-pushed the fb/create-method-middleware branch from fb74b9f to a8f3aa6 Compare April 21, 2026 08:16
rekmarks and others added 6 commits April 21, 2026 11:52
…essenger actions

Replace the hook-based permission middleware factory with a standalone
`createPermissionMiddleware` export that dispatches through messenger
actions (`PermissionController:executeRestrictedMethod` and
`PermissionController:hasUnrestrictedMethod`). Removes the
`createPermissionMiddleware` property from `PermissionController`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Now that the permission middleware invokes restricted methods through
the messenger, `getRestrictedMethod` has no remaining external consumers
and is made `#`-private. Its caller signature is tightened so
`requestingOrigin` is required, eliminating a dead optional-origin
branch in `#getTypedPermissionSpecification`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add a `JsonRpcEngineV2` variant of the standalone permission middleware
factory that uses the same messenger actions as the v1 factory. The
existing `createPermissionMiddleware` is marked `@deprecated` in favor
of the v2 variant.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@rekmarks rekmarks force-pushed the rekm/permission-methodmiddleware branch from 706f8dc to f04c517 Compare April 21, 2026 18:52
- Add v2 middleware tests for caveats, method-not-found, and undefined result
- Add direct messenger action tests for hasUnrestrictedMethod and executeRestrictedMethod
- Clarify changelog wording for standalone createPermissionMiddleware
- Update ARCHITECTURE.md middleware example to use V2 and introduce the messenger
- Clarify hasUnrestrictedMethod JSDoc about unknown methods
@rekmarks rekmarks marked this pull request as ready for review April 21, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant